#ifndef _My_Button_H
#define _My_Button_H

#include <Arduino.h>
#include <FunctionalInterrupt.h>
#include "OLED/MyDisplay.h"

#define BUTTON_INC_PIN 2
#define BUTTON_DEC_PIN 4
#define BUTTON_SET_PIN 12
#define BUTTON_FUNC_PIN 0

// 中断过程不能做太多事情，不然可能还没执行完，又一个中断来了就会出错。如果确实需要做，就要先关掉中断，做完后再开启

class MyButton
{
private:
    //按钮pin和初始时间
    unsigned long preMillis;
    uint8_t Mode;
    void onButtonAct();
    boolean setButtonPressed;

public:
    MyButton(void);
    ~MyButton();
    
    void IRAM_ATTR isr_func();
    void IRAM_ATTR isr_inc();
    void IRAM_ATTR isr_dec();
    void IRAM_ATTR isr_set();

    int increaseCount, decreaseCount;

    void onButton(); //按键相应
    uint8_t getMode() { return this->Mode; }
    void setMode(uint8_t mode) { this->Mode = mode; }
    boolean isSetButtonPressed() { return this->setButtonPressed; }
    void resetSetButton() { this->setButtonPressed = false; }
};

#endif